package com.bookseek.xreader.utils;

import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.SPUtils;
import com.bookseek.xreader.R;
import com.bookseek.xreader.consts.XreaderConts;

import java.util.UUID;

public class NbUtils {

    private static String SPNAME="xreadernb";


    private static String APPID = "appid";
    private static String MID = "mid";

    private static String FONT_WEN_SIZE_SP = "font_wen_size_sp";
    private static String FONT_YI_SIZE_SP = "font_yi_size_sp";

    private static String FONT_COLOR_WEN = "font_color_wen";
    private static String FONT_COLOR_YI = "font_color_yi";

    private static String SHOW_YIWEN = "show_yiwen";
    private static String FONT_ZH_TYPE = "font_zh_type";

    private static String READER_BG_COLOR = "reader_bg_color";


    public static void setFontColorWen(int fontColorWen){
        SPUtils.getInstance(SPNAME).put(FONT_COLOR_WEN,fontColorWen);
    }
    public static int getFontColorWen(){
        return SPUtils.getInstance(SPNAME).getInt(FONT_COLOR_WEN, XreaderConts.WY_TYPE_WEN_DEFAULT_COLOR);
    }

    public static void setFontColorYi(int fontColorYi){
        SPUtils.getInstance(SPNAME).put(FONT_COLOR_YI,fontColorYi);
    }
    public static int getFontColorYi(){
        return SPUtils.getInstance(SPNAME).getInt(FONT_COLOR_YI,XreaderConts.WY_TYPE_YI_DEFAULT_COLOR);
    }


    public static void setReaderBgColor(Integer readerBgColor){
        SPUtils.getInstance(SPNAME).put(READER_BG_COLOR,readerBgColor);
    }
    public static Integer getReaderBgColor(){
        return SPUtils.getInstance(SPNAME).getInt(READER_BG_COLOR, R.drawable.read_bg_01);
    }
    public static void setFontZhType(int type){
        SPUtils.getInstance(SPNAME).put(FONT_ZH_TYPE,type);
    }
    public static int getFontZhType(){
        return SPUtils.getInstance(SPNAME).getInt(FONT_ZH_TYPE,0);
    }

    public static void setShowYiwen(boolean flag){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        spUtils.put(SHOW_YIWEN,flag);
    }
    public static boolean getShowYiwen(){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        return spUtils.getBoolean(SHOW_YIWEN,true);
    }
    public static void setFontWenSizeSp(float fontSizeSp){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        spUtils.put(FONT_WEN_SIZE_SP,fontSizeSp);
    }
    public static float getFontWenSizeSp(){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        return spUtils.getFloat(FONT_WEN_SIZE_SP,20.0f);
    }
    public static  void setFontYiSizeSp(float fontSizeSp){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        spUtils.put(FONT_YI_SIZE_SP,fontSizeSp);
    }

    public static  float getFontYiSizeSp(){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        return spUtils.getFloat(FONT_YI_SIZE_SP,14.0f);
    }

    public static String getMid(){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        String id = spUtils.getString(MID,null);
        if(JkhlUtils.isBlank(id)){
            id = UUID.randomUUID().toString().replace("-","");
            spUtils.put(MID,id);
        }
        return id;
    }
    public static String getDeviceUniqId(){
        SPUtils spUtils = SPUtils.getInstance(SPNAME);
        String id = spUtils.getString(APPID,null);

        if(JkhlUtils.notBlank(id)){
            DLog.info("appid==>",id);
            return id;
        }
        if(JkhlUtils.isBlank(id)){
            id = DeviceUtils.getAndroidID();
            DLog.info("deviceAndroid =>",id);
        }
        if(JkhlUtils.isBlank(id)){
            String uuid = UUID.randomUUID().toString().replace("[-]","");
            id = uuid;
            DLog.info("uuid =>",id);
        }
        spUtils.put(APPID,id);
        return id;
    }


}
